package cvsexercise6;

public class MoreControlledRepetition {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		/* Write out a start message to the console */
		System.out.println("Exercise 6 - Controlled Repetition");
		
		/* Declare and initialize an M x N array of Strings
		 * with the values {"Homer", "Marge", "Bart", "Lisa", "Maggie"}, 
		 * {"Peter", "Lois", "Meg", "Chris", "Stewie", "Brian"},
		 * {"Stan", "Kyle", "Cartman", "Kenny"}
		 * NOTE: use an initializer list to create the array!
		 */
		String[][] myCartoonArray = {{"Homer", "Marge", "Bart", "Lisa", "Maggie"}, 
				                     {"Peter", "Lois", "Meg", "Chris", "Stewie", "Brian"},
				                     {"Stan", "Kyle", "Cartman", "Kenny"}};
		
		/* Use a while loop to write out the values of each row of the array
		 * and write out a title for each row of the array before listing the values
		 * NOTE: you will need to used nested while loops!
		 * NOTE: you will need to initialize the control variable outside of each while loop 
		 *       and increment it within each respective while loop
		 */
		
		/* Initialize the control variable */
		int idxRow = 0;
		
		/* Outer loop to handle rows */
		while (idxRow < myCartoonArray.length) {
			
			/* Initialize the control variable for the inner loop */
			int idxCol = 0;
			
			/* Based on the row index, print out a title for the contents of the array */
			if (idxRow == 0) {
				System.out.println("The cast of The Simpsons:");
			} else {
				if (idxRow == 1) {
					System.out.println("The cast of Family Guy:");
				} else {
					System.out.println("The cast of Southpark");
				}
			}
			
			/* Inner loop to print out the contents of each row */
			while (idxCol < myCartoonArray[idxRow].length) {
				System.out.println("myCartoonArray[" + idxRow + "][" + idxCol + "] = " + myCartoonArray[idxRow][idxCol]);
				
				/* Increment the inner loop control variable */
				idxCol++;
			}
			
			/* Increment the outer loop control variable */
			idxRow++;
		}
		
		/* Write out a completed message to the console */
		System.out.println("Exercise 6 - Controlled Repetition");
	}
}
